<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright 2011 KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: index.tpl 2011-03-09 01:11:30 idris $
 * @author     Idris
 */
?>

<h2>
  <?php echo $this->translate('Voting Plugin') ?>
</h2>

<?php if( count($this->navigation) ): ?>
<div class='tabs'>
	<?php
	// Render the menu
	//->setUlClass()
	echo $this->navigation()->menu()->setContainer($this->navigation)->render()
	?>
</div>
<?php endif; ?>

<script type="text/javascript">
var currentOrder = '<?php echo $this->order ?>';
var currentOrderDirection = '<?php echo $this->order_direction ?>';
var changeOrder = function(order, default_direction) {
	if( order == currentOrder ) {
		$('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
	} else {
		$('order').value = order;
		$('order_direction').value = default_direction;
	}
	$('filter_form').submit();
}

function multiModify()
{
  var multimodify_form = $('multimodify_form');
  if (multimodify_form.submit_button.value == 'delete')
  {
    return confirm('<?php echo $this->string()->escapeJavascript($this->translate("Are you sure you want to delete the selected votings?")) ?>');
  }
}

function selectAll()
{
  var i;
  var multimodify_form = $('multimodify_form');
  var inputs = multimodify_form.elements;
  for (i = 1; i < inputs.length - 1; i++) {
    if (!inputs[i].disabled) {
      inputs[i].checked = inputs[0].checked;
    }
  }
}
</script>

<p>
  <?php echo $this->translate("VOTING_VIEWS_SCRIPTS_ADMINMANAGE_INDEX_DESCRIPTION") ?>
</p>

<br />

<?php if($this->paginator && $this->paginator->getTotalItemCount()>0): ?>

<div class='admin_search'>
  <?php echo $this->form->render($this) ?>
</div>

<br />

<div class='admin_results'>
  <div>
    <?php $votingCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s voting found", "%s votings found", $votingCount), ($votingCount)) ?>
  </div>
  <div>
    <?php echo $this->paginationControl($this->paginator); ?>
  </div>
</div>

<br />


<div class="admin_table_form">
<form id='multimodify_form' method="post" action="<?php echo $this->url(array('action'=>'multi-modify'));?>" onSubmit="return multiModify();">
  <table class='admin_table'>
    <thead>
      <tr>
        <th style='width: 1%;'><input onclick="selectAll()" type='checkbox' class='checkbox'></th>
        <th style='width: 1%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('challenge_id', 'DESC');"><?php echo $this->translate("ID") ?></a></th>
        <th><a href="javascript:void(0);" onclick="javascript:changeOrder('title', 'ASC');"><?php echo $this->translate("Title") ?></a></th>
        <th class="admin_table_centered"><?php echo $this->translate("Type") ?></th>
        <th class="admin_table_centered"><?php echo $this->translate("Owner") ?></th>
				<th style='width: 1%;' class='admin_table_centered'><?php echo $this->translate("Featured") ?></th>
        <th style='width: 1%;' class='admin_table_centered'><?php echo $this->translate("Approved") ?></th>
        <th style='width: 1%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('creation_date', 'DESC');"><?php echo $this->translate("Creation Date") ?></a></th>
				<th style='width: 1%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('starttime', 'DESC');"><?php echo $this->translate("Start Time") ?></a></th>
				<th style='width: 1%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('endtime', 'DESC');"><?php echo $this->translate("End Time") ?></a></th>
        <th style='width: 1%;' class='admin_table_options'><?php echo $this->translate("Options") ?></th>
      </tr>
    </thead>
    <tbody>
      <?php if( count($this->paginator) ): ?>
        <?php foreach( $this->paginator as $item ): ?>
          <tr>
            <td><input name='modify[<?php echo $item->getIdentity();?>]' value="<?php echo $item->getIdentity();?>" type='checkbox' class='checkbox' /></td>
            <td><?php echo $item->getIdentity(); ?></td>
            <td class='admin_table_bold'>
              <?php
                $display_name = $item->getTitle();
                $display_name = Engine_String::strlen($display_name) > 20 ? Engine_String::substr($display_name, 0, 20) . '...' : $display_name;
                echo $this->htmlLink($item->getHref(), $display_name, array('target' => '_blank'))
              ?>
            </td>
            <td class='admin_table_centered'>
              <?php echo $this->translate('vote_type_'.$item->type); ?>
            </td>
						<td class='admin_table_centered'>
							<?php
                $display_name = $this->item('user', $item->user_id)->getTitle();
                $display_name = Engine_String::strlen($display_name) > 20 ? Engine_String::substr($display_name, 0, 20) . '...' : $display_name;
                echo $this->htmlLink($this->item('user', $item->user_id)->getHref(), $display_name, array('target' => '_blank'))
              ?>
            </td>
						<td class='admin_table_centered'>
							<?php $src = $item->featured ? 'featured.png' : 'not_featured.png'; ?>
							<?php echo $this->htmlImage($this->baseUrl().'/application/modules/Vote/externals/images/'.$src, ''); ?>
						</td>
            <td class='admin_table_centered'>
							<?php $src = $item->approved ? 'approve.png' : 'disapprove.png'; ?>
							<?php echo $this->htmlImage($this->baseUrl().'/application/modules/Vote/externals/images/'.$src, ''); ?>
						</td>
            <td>
							<?php echo $item->creation_date ?>
						</td>
						<td>
							<?php echo $item->starttime; ?>
						</td>
						<td>
							<?php echo $item->endtime; ?>
						</td>
            <td class='admin_table_options admin_vote_options'>
							<?php echo $this->htmlLink($this->url(array('module' => 'vote', 'controller' => 'manage', 'format' => 'smoothbox', 'action' => 'delete', 'challenge_id' => $item->getIdentity()), 'admin_default'), '', array('class' => 'remove option smoothbox', 'title' => 'Delete This Voting') ); ?>
							<?php
							$class = 'option ';
							if (!$item->featured){
						  	$class .= 'set-featured';
							} else {
								$class .= 'set-unfeatured';
							}
							?>
							<?php echo $this->htmlLink($this->url(array('module' => 'vote', 'controller' => 'manage', 'action' => 'featured', 'challenge_id' => $item->getIdentity(), 'featured' => (int)(!$item->featured)), 'admin_default'), '', array('class' => $class, 'title' => 'Set Featured This Voting') ); ?>
							<?php
							$class = 'option ';
							if (!$item->approved){
						  	$class .= 'approve';
							} else {
								$class .= 'disapprove';
							}
							?>
							<?php echo $this->htmlLink($this->url(array('module' => 'vote', 'controller' => 'manage', 'action' => 'approve', 'challenge_id' => $item->getIdentity(), 'approve' => (int)(!$item->approved)), 'admin_default'), '', array('class' => $class, 'title' => 'Set Featured This Voting') ); ?>
            </td>
          </tr>
        <?php endforeach; ?>
      <?php endif; ?>
    </tbody>
  </table>
  <br />
  <div class='buttons'>
		<button type='submit' name="submit_button" value="delete"><?php echo $this->translate("Delete Selected"); ?></button>
  </div>
</form>
</div>

<?php else: ?>

<div class="tip">
	<span>
		<?php echo $this->translate("There are no votings created by your members yet.") ?>
	</span>
</div>

<?php endif; ?>